package models

import (
	"192.168.1.75/go-pkg/helper"
	"gorm.io/gorm"
)

// FloorPosition 楼层位置
type FloorPosition struct {
	ID        string  `json:"id" gorm:"column:id;primaryKey;type:int;size:64;comment:主键id"`
	FloorID   string  `json:"floor_id,omitempty" gorm:"column:floor_id;type:int;size:64;comment:楼层id"`
	Name      string  `json:"name,omitempty" gorm:"column:name;type:string;size:40;comment:位置点名称"`
	Type      int     `json:"type,omitempty" gorm:"column:type;type:int;size:8;default:0;comment:位置类型,1-商铺 2-步梯 3-扶梯 4-客梯"`
	PositionX float64 `json:"position_x,omitempty" gorm:"column:position_x;type:float;size:64;comment:x轴坐标"`
	PositionY float64 `json:"position_y,omitempty" gorm:"column:position_y;type:float;size:64;comment:y轴坐标"`
	CreatedAt int64   `json:"created_at,omitempty" gorm:"column:created_at;autoCreateTime;type:int;size:64;comment:创建时间"`
	UpdatedAt int64   `json:"updated_at,omitempty" gorm:"column:updated_at;autoUpdateTime;type:int;size:64;comment:更新时间"`
}

// TableName 表名
func (FloorPosition) TableName() string {
	return "floor_position"
}

// BeforeCreate 自增id
func (l *FloorPosition) BeforeCreate(tx *gorm.DB) (err error) {
	if l.ID != "" {
		return nil
	}
	// 用户id为空时，自动添加用户id
	uuid, err := helper.UUID{}.String()
	if err != nil {
		return err
	}
	l.ID = uuid
	return nil
}

// 模式自动注册
func init() {
	Models = append(Models, &FloorPosition{})
}
